<?php
$f = "facebox";
if (isset($_GET['aj'])) {
    include("ajaxinlcudes.php");
    $f = "facebox1";
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$re_sublinks = getSubCategoryFind(1, 0, "YES");
$row_re_sublinks = mysql_fetch_assoc($re_sublinks);

$colname_rs_up = "-1";
if (isset($_GET['itemid']) &&((@$_GET['page'] == "category") || isset($_GET['aj']))) {
$colname_rs_up = $_GET['itemid'];
$itemid = $_GET['itemid'];
} else {
    $colname_rs_up = $row_rs_up["category_id"];

    $itemid = $row_rs_up["category_id"];
}
$rs_cat_up = getCategoryDetails($colname_rs_up);
$row_rs_cat_up = mysql_fetch_assoc($rs_cat_up);
$totalRows_rs_up = mysql_num_rows($rs_cat_up);
$parentid = $row_rs_cat_up["category_id"];


if (isset($_GET['pid']))
    $itemid = $_GET['pid'];
?>
<div id="ptitle"><?php echo htmlentities($row_rs_cat_up['category_name'], ENT_COMPAT, 'utf-8'); ?></div>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
        <td width="63%" valign="top"><form action="?page=category&amp;itemid=<?php echo $itemid; ?>" method="post" name="form1" id="form1">
                <input type="hidden" name="MM_update" value="frmcatupdate" />
                <input type="hidden" name="categoryid" value="<?php echo $row_rs_cat_up['category_id']; ?>" />
                <a href="pages/category_add.php?aj&amp;pid=<?php echo $row_rs_cat_up['category_id']; ?>" rel="<?php echo $f; ?>">Add sublinks</a>
                <table align="center">
                    <tr valign="baseline">
                        <td width="129" align="left" nowrap="nowrap">Category id:</td>
                        <td width="275"><?php echo $row_rs_cat_up['category_id']; ?></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">Category Name:</td>
                        <td><input type="text" name="categoryname" value="<?php echo htmlentities($row_rs_cat_up['category_name'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">List Type</td>
                        <td><select name="listtype" id="listtype" >
                                <?php do {
 ?>
                                    <option value="<?php echo $row_re_sublinks["category_id"]; ?>" <?php
                                    if (!(strcmp($row_re_sublinks["category_id"], $row_rs_cat_up['list_type']))) {
                                        echo "SELECTED";
                                    }
                                ?>><?php echo $row_re_sublinks["category_name"]; ?></option>
<?php } while ($row_re_sublinks = mysql_fetch_assoc($re_sublinks)); ?>
                            </select></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">Published:</td>
                        <td><label>
                                <select name="ispublished" id="ispublished">
                                    <option value="yes" <?php if ($row_rs_cat_up['is_published'] == "yes")
                                        echo "SELECTED"; ?>>Yes</option>
                                    <option value="no" <?php if ($row_rs_cat_up['is_published'] == "no")
                                        echo "SELECTED"; ?>>No</option>
                                </select>
                            </label>         </td>
                    </tr>
                    <tr valign="baseline">
                        <td align="left" valign="top" nowrap="nowrap">Category Description</td>
                        <td><label>
                                <textarea name="description" id="description"><?php echo htmlentities($row_rs_cat_up['category_description'], ENT_COMPAT, 'utf-8'); ?></textarea>
                            </label></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">Allow Comment</td>
                        <td><select name="allowcomment">
                                <option value="yes" <?php
                                    if (!(strcmp("yes", $row_rs_cat_up['allow_comment']))) {
                                        echo "SELECTED";
                                    }
?>>Yes</option>
                                    <option value="no" <?php
                                    if (!(strcmp("no", $row_rs_cat_up['allow_comment']))) {
                                        echo "SELECTED";
                                    }
?>>No</option>
                            </select></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">RSS</td>
                        <td><select name="rss">
                                <option value="yes" <?php
                                    if (!(strcmp("yes", $row_rs_cat_up['is_rss']))) {
                                        echo "SELECTED";
                                    }
?>>Yes</option>
                                    <option value="no" <?php
                                    if (!(strcmp("no", $row_rs_cat_up['is_rss']))) {
                                        echo "SELECTED";
                                    }
?>>No</option>
                            </select></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">Category icon:</td>
                        <td><input type="text" name="categoryicon" value="<?php echo htmlentities($row_rs_cat_up['category_icon'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">Parent:</td>
                        <td>
                            <select name="parentid" id="parentid">
                                <option value="0"  <?php
                                    if (0 == $row_rs_cat_up['parent_id']) {
                                        echo"SELECTED";
                                        $p = "None";
                                    } ?>>None</option>
                                        <?php
                                        $rs = loadRelatedParent($row_rs_cat_up['parent_id']);
                                        $row = mysql_fetch_assoc($rs);
                                        do {
                                        ?>
                                            <option value="<?php echo $row["category_id"]; ?>"  <?php
                                            if ($row["category_id"] == $row_rs_cat_up['parent_id']) {
                                                echo"SELECTED";
                                                $p = $row["category_name"];
                                            }
                                        ?>><?php echo $row["category_name"]; ?></option>
                                        <?php
                                        } while ($row = mysql_fetch_assoc($rs))
                                        ?>
<?php ?>
                            </select><a href="pages/category_update.php?aj&amp;itemid=<?php echo $row_rs_cat_up['parent_id']; ?>" rel="facebox"><?php echo $p ?></a>
                        </td>
                    </tr>
                    <tr valign="baseline">
                        <td nowrap="nowrap" align="left">&nbsp;</td>
                        <td><input type="submit" value="Update record" /></td>
                    </tr>
                </table>
            </form></td>
        <td width="37%" valign="top"><?php include("sublinks.php") ?></td>
    </tr>
</table>
<?php
                                        mysql_free_result($rs_cat_up);
?>